import service from "@/utils/http";
import type {
    DataType,
    RecommendedType,
    AdvertisingParamsType,
    AdvertisingType,
    VideoType,
    LiveType,
    LiveForecastsType,
    LiveOfficialType,
    topTagListsDataType,
    GranaryModuleType0,
    GranaryModuleType1,
    GranaryModuleType2,
    GranaryNaviDataType,
    HomeItemType,
    HomeItemCommentsType
} from "@/typings"

export const Api = {
    // 获取推荐页数据
    getRecommended: () => {
        return service<RecommendedType>({
            url: '/api/recommend/exploreRecom.json?product=lofter-android-7.1.9',
            method: 'get'
        })
    },

    // 获取广告数据 通用！
    getAdvertising: (params: AdvertisingParamsType) => {
        return service<AdvertisingType[], AdvertisingType[]>({
            url: "/api/v1.1/yitou/madr",
            method: 'post',
            headers: {
                "isVip": "false",
                "X-User-Agent": "android/7.1.9.345/1.1 (ffffffff-e798-102c-ffff-ffffc5cc5f93;LENOVO L79031;900x1600) (android;7.1.2;zh-CN) (com.lofter.android;baidu)"
            },
            params: params
        })
    },

    // 获取视频数据
    getVideo: () => {
        return service<VideoType>({
            url: "/api/recommend/videoFlow.json",
            method: 'get'
        })
    },

    // 获取推荐页正在直播数据
    getLive: () => {
        return service<LiveType>({
            url: "/api/zhibo/liveMonth/live",
            method: 'get'
        })
    },

    // 获取推荐页forecast预直播数据 
    getForecastLive: () => {
        return service<LiveForecastsType>({
            url: "/api/zhibo/liveMonth/forecast?limit=20",
            method: 'get'
        })
    },

    // 获取推荐页official官方直播数据
    getOfficialLive: () => {
        return service<LiveOfficialType>({
            url: "/api/zhibo/liveMonth/replay?limit=18",
            method: 'get'
        })
    },

    // 发现页通用数据
    getgGneralData: (params: { domainId: number | undefined }) => {
        return service<{ list: DataType[], topTagLists: topTagListsDataType[] }>({
            url: "/api/recommend/domainPosts.json",
            method: 'post',
            headers: {
                "content-type": "application/x-www-form-urlencoded;charset=utf-8"
            },
            params: params
        })
    },


    // 获取粮仓页数据
    getGranary: () => {
        return service<{ list: GranaryModuleType0[] | GranaryModuleType1[] | GranaryModuleType2[], navi: GranaryNaviDataType[] }>({
            url: "/api/recommend/grainStore.json?offset=0&lastModuleType=0",
            method: 'get'
        })
    },


    //获取home子页数据
    getHomeItem: (params: { blogdomain: string, postid: number | undefined }) => {
        return service<HomeItemType, HomeItemType>({
            url: "/api/oldapi/post/detail.api",
            method: 'post',
            headers: {
                "content-type": "application/x-www-form-urlencoded"
            },
            params: params
        })
    },

    //获取comments 评论数据
    getHomeComments: (params: { postId: number | undefined, blogId: number }) => {
        return service<{ list: HomeItemCommentsType[], hotList: HomeItemCommentsType[] }>({
            url: "/api/comment/l1/hotnew.json",
            method: 'get',
            headers: {
                "lofter-phone-login-auth": "_A4rW3QNNOxbkTSGNVgdQXwBQ8KxQpHQiGRNuk4p1a5vTuykpggkZBCltWKCHooZOSAZyct08HQgx46VzX9UyE2PiLcFROrg"
            },
            params: params
        })
    },

    //获取comments 全部评论数据
    getHomeAllComments: (params: { postId: number | undefined, blogId: number }) => {
        return service<{ list: HomeItemCommentsType[], hotList: HomeItemCommentsType[] }>({
            url: "/api/comment/l1/page.json",
            method: 'get',
            headers: {
                "lofter-phone-login-auth": "_A4rW3QNNOxbkTSGNVgdQXwBQ8KxQpHQiGRNuk4p1a5vTuykpggkZBCltWKCHooZOSAZyct08HQgx46VzX9UyE2PiLcFROrg"
            },
            params: params
        })
    },

    //Send数据 发评论
    getHomeSendComments: (params: { postId: number | undefined, blogId: number, content: string }) => {
        return service({
            url: "/api/comment/add.json",
            method: 'post',
            headers: {
                "lofter-phone-login-auth": "_A4rW3QNNOxbkTSGNVgdQXwBQ8KxQpHQiGRNuk4p1a5vTuykpggkZBCltWKCHooZOSAZyct08HQgx46VzX9UyE2PiLcFROrg",
                "content-type": "application/x-www-form-urlencoded;charset=utf-8",
            },
            params: params
        })
    },


    //获取搜索页面数据 search data
    getSearchData: () => {
        return service({
            url: "/api/newapi/hotsearch/ranklist.json",
            method: 'get',
        })
    },

    //搜索api search
    getSearch: (params: { key: string }) => {
        return service({
            url: "/api/newsearch/sug.json?",
            method: 'post',
            params: params
        })
    },

    //搜索api search
    postSearch: (params: { key: string }) => {
        return service({
            url: "/api/newsearch/v2/all.json",
            method: 'post',
            params: params
        })
    },



    //视频
    getVideoDetails: (params: { permalink: string | undefined }) => {
        return service({
            url: "/api/recommend/postVideoFlow.json",
            method: 'get',
            params: params
        })
    },
}

